package com.example.education.Controller;


import com.example.education.Bean.CollegeInfo;
import com.example.education.Bean.packaginggroup.PackagingString;
import com.example.education.service.CollegeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/collegeinfo")
@CrossOrigin
public class CollegeInfoController {
    @Autowired
    private CollegeInfoService collegeInfoService;


    @PostMapping
    public Integer save(@RequestBody(required = false) CollegeInfo collegeInfo) {//将传回来的json对象转

        return collegeInfoService.insert(collegeInfo);
    }

    //根据学校名字查找学校
    @PostMapping("/collegeName")
    public CollegeInfo selectByCollegeName(@RequestBody PackagingString packageString) {
        System.out.println(packageString.getString());
        CollegeInfo collegeInfo = collegeInfoService.select(packageString.getString());
        System.out.println(collegeInfo);
        return collegeInfo;
    }


    //热门学校
    @GetMapping()
    public CollegeInfo[] selectTopTen() {
        return collegeInfoService.selectTopTen();
    }

}

